package com.artron.mediaartron.ui.fragment.factory;

import com.artron.mediaartron.ui.fragment.made.CustomSelectionVerticalFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-09-25.
 */

public class CustomSelectionVerticalFragmentFactory {

    private static CustomSelectionVerticalFragmentFactory instance;
    private List<CustomSelectionVerticalFragment> mFragments;

    private CustomSelectionVerticalFragmentFactory(int length){
        mFragments = new ArrayList<>();
        for (int x = 0; x < length; x++) {
            mFragments.add(CustomSelectionVerticalFragment.newInstance());
        }

    }
    public static CustomSelectionVerticalFragmentFactory getInstance(int length){
        if (instance == null) {
            synchronized (CustomSelectionVerticalFragmentFactory.class) {
                if (instance == null) {
                    instance = new CustomSelectionVerticalFragmentFactory(length);
                }
            }
        }
        return instance;
    }

    public static CustomSelectionVerticalFragmentFactory getInstance() {
        return instance;
    }

    public CustomSelectionVerticalFragment getFragment(int position) {
        return mFragments.get(position);
    }

    public List<CustomSelectionVerticalFragment> getFragments() {
        return mFragments;
    }

    public void destroy() {
        mFragments.clear();
        instance = null;
    }
}
